layui.use(['table', 'admin', 'ax'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;

    var dispatchNumber = Feng.getUrlParam("dispatchNumber");
    var xlbClientId = Feng.getUrlParam("xlbClientId");

    /**
     * 空闲车
     */
    var UpdateqsrSel = {
        tableId: "updateqsrSelTable"
    };

    /**
     * 初始化表格的列
     */
    UpdateqsrSel.initColumn = function () {
        return [[
            {field: 'id', hide: true, title: '主键'},
            {align: 'center', toolbar: '#tableBar', title: '操作'},
            {field: 'userName', title: '员工姓名', style:'font-weight: 600;'},
            {field: 'employeeName', title: '员工真实姓名', style:'font-weight: 600;'},
            {field: 'userTel', title: '员工手机号', style:'font-weight: 600;'},
        ]];
    };

    /**
     * 点击查询按钮
     */
    UpdateqsrSel.search = function () {
        var queryData = {};
        table.reload(UpdateqsrSel.tableId, {
            where: queryData,
             done:function () {
            }
        });
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + UpdateqsrSel.tableId,
        url: Feng.ctxPath + '/tDispatch/updatexsrList?dispatchNumber=' + dispatchNumber + '&xlbClientId=' + xlbClientId,
        page: false,
        limit: 1000,
        height: "full-60",
        cellMinWidth: 100,
        cols: UpdateqsrSel.initColumn()
    });

    // 搜索按钮点击事件
    // $('#btnSearch').click(function () {
    //     UpdateqsrSel.search();
    // });
    // UpdateqsrSel.search();
    // 工具条点击事件
    table.on('tool(' + UpdateqsrSel.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;
        if (layEvent === 'xianze') {
            layer.confirm('确定要更换签收人吗？', function(index){
            	layer.close(index);
            	var msg;
                $.ajax({
                	url:Feng.ctxPath + "/tDispatch/updatexsr",
					data:{
                        dispatchNumber:dispatchNumber,
                        xlbClientId:xlbClientId,
                        userTel:data.userTel
                    },
                	cache: false,
                	dataType:"json",
                	beforeSend:function(){
                		msg = layer.msg('提交中。。。请耐心等待', {
                			  icon: 16,
                			  shade: [0.2,'#000'], //0.1透明度的白色背景
                			  time: false
                		});
                	},
                	success:function(data){
                    	layer.close(msg); 
                		if (data.success) {
							parent.submit = 1
			            	Feng.success("提交成功!");
					    	var Index = parent.layer.getFrameIndex(window.name);
					        parent.layer.close(Index);
						} else {
  		                    Feng.error("提交失败！"+data.message);
						}
                	},
                	error:function(data){
                    	layer.close(msg); 
                        Feng.error("提交失败！" + data.responseJSON.message)
                	}
                })
            }); 
        } 
    });

});
